<div class="main layui-clear">
    <div class="fly-panel" pad20="" style="padding-top: 5px;">
        <div class="layui-form layui-form-pane">
            <div class="layui-tab layui-tab-brief" lay-filter="user">
                <ul class="layui-tab-title">
                    <li class="layui-this">
                        发表新帖
                    </li>
                </ul>
                <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                    <div class="layui-tab-item layui-show">
                        <form action="" method="post">
                            <div class="layui-form-item">
                                <label for="L_title" class="layui-form-label">
                                    标题
                                </label>
                                <div class="layui-input-block">
                                    <input type="text" id="L_title" name="title" required="" lay-verify="required"
                                    autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <div class="layui-input-block">
                                    <!-- <div class="layui-unselect fly-edit">
                                        <span type="face" title="插入表情">
                                            <i class="iconfont icon-yxj-expression" style="top: 1px;">
                                            </i>
                                        </span>
                                        <span type="picture" title="插入图片：img[src]">
                                            <i class="iconfont icon-tupian">
                                            </i>
                                        </span>
                                        <span type="href" title="超链接格式：a(href)[text]">
                                            <i class="iconfont icon-lianjie">
                                            </i>
                                        </span>
                                        <span type="code" title="插入代码或引用">
                                            <i class="iconfont icon-emwdaima" style="top: 1px;">
                                            </i>
                                        </span>
                                        <span type="hr" title="插入水平线">
                                            hr
                                        </span>
                                        <span type="yulan" title="预览">
                                            <i class="iconfont icon-yulan1">
                                            </i>
                                        </span>
                                    </div> -->
                                    <textarea id="L_content" name="content" required="" lay-verify="content"
                                    placeholder="请输入内容" class="layui-textarea fly-editor" style="height: 260px;"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">
                                        所在类别
                                    </label>
                                    <div class="layui-input-block" style="width: 190px;">
                                        
                                      <!-- <select lay-verify="required" name="class" >
                                            <option>
                                            </option>
                                            <option value="0">提问</option>
                                            <option value="1">建议</option>
                                            <option value="99">分享</option>
                                            <option value="100">讨论</option>
                                        </select> -->
                                            
                                        <select lay-verify="required" name="cid" >
                                            <option>
                                            </option>
                                            <?php foreach ($cates as $row) { ?>
                                                <optgroup label="<?php echo $row['cname'] ?>">
                                                <?php foreach ($row['son'] as $v) { ?>
                                                    <option value="<?php echo $v['id'] ?>"><?php echo $v['cname'] ?></option>
                                                <?php } ?>
                                                </optgroup>
                                            <?php } ?>
                                        </select>


                                        <!-- <div class="layui-unselect layui-form-select">
                                            <div class="layui-select-title">
                                                <input type="text" placeholder="请选择" value="" readonly="" class="layui-input layui-unselect">
                                                <i class="layui-edge">
                                                </i>
                                            </div>
                                            <dl class="layui-anim layui-anim-upbit">
                                                <dd lay-value="" class="layui-select-tips">
                                                    请选择
                                                </dd>
                                                <dd lay-value="0" class="">
                                                    提问
                                                </dd>
                                                <dd lay-value="1" class="">
                                                    建议
                                                </dd>
                                                <dd lay-value="99" class="">
                                                    分享
                                                </dd>
                                                <dd lay-value="100" class="">
                                                    讨论
                                                </dd>
                                            </dl>
                                        </div> -->
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">
                                        悬赏飞吻
                                    </label>
                                    <div class="layui-input-inline" style="width: 190px;">
                                        <select name="kiss_num">
                                            <option value="10">10
                                            </option>
                                            <option value="20">20
                                            </option>
                                            <option value="30">30
                                            </option>
                                            <option value="50">50
                                            </option>
                                            <option value="80">80
                                            </option>
                                        </select>
                                        <!-- <div class="layui-unselect layui-form-select">
                                            <div class="layui-select-title">
                                                <input type="text" placeholder="请选择" value="10" readonly="" class="layui-input layui-unselect">
                                                <i class="layui-edge">
                                                </i>
                                            </div>
                                            <dl class="layui-anim layui-anim-upbit">
                                                <dd lay-value="10" class="layui-this">
                                                    10
                                                </dd>
                                                <dd lay-value="20" class="">
                                                    20
                                                </dd>
                                                <dd lay-value="30" class="">
                                                    30
                                                </dd>
                                                <dd lay-value="50" class="">
                                                    50
                                                </dd>
                                                <dd lay-value="80" class="">
                                                    80
                                                </dd>
                                            </dl>
                                        </div> -->
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">
                                        发表后无法更改飞吻
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_vercode" class="layui-form-label">
                                    人类验证
                                </label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_vercode" name="verify" required="" lay-verify="required"
                                    placeholder="请回答后面的问题" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid">
                                    <span style="color: #c00;">
                                        <?php echo $question ?>
                                    </span>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <button class="layui-btn" lay-filter="add" lay-submit="">
                                    立即发布
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    //Demo
    layui.use(['form','layer','layedit'], function(){
        $ = layui.jquery;
      var form = layui.form
      ,layer = layui.layer;
      var layedit = layui.layedit;

      //插入图片接口 [把图片放在服务器 返回图片地址]
      layedit.set({
          uploadImage: {
            url: '{:U('home/jie/uploadImage')}' //接口url处理上传图片的方法 上传成功返回JSON
            ,type: 'POST' //默认post
          }
        });
        //注意：layedit.set 一定要放在 build 前面，否则配置全局接口将无效。
      index = layedit.build('L_content'); //建立编辑器

      //自定义验证规则
    //   form.verify({
    //   content: function(value, item){ //value：表单的值、item：表单的DOM对象
    //     if (value=='') {
    //         return '问题描述不能为空!';
    //     }
    //   }
    //   //我们既支持上述函数式的方式，也支持下述数组的形式
    //   //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
    //   ,pass: [/(.+){6,12}$/, '密码必须6到16位!'] 
    //   ,repass: function(value){
    //     if($('#L_pass').val()!=$('#L_repass').val()){
    //         return '两次密码不一致!';
    //     }
    //   }
    //   ,verify: function(value, item){
    //     if (value=='') {
    //         return '人类验证不能为空!';
    //     }
    //   }
        
      
    // });
      
      //监听提交
      form.on('submit(add)', function(data){
        // layer.msg(JSON.stringify(data.field));
        
        //判断发布内容为空时返回提示
        content = layedit.getContent(index);
        //alert(content);
        if (content=='') {
            layer.msg('发帖内容不能为空!',{icon: 5},function () {
                     // body...
                 });
            return false;
        };

        //同步内容 更改什么抓到什么
        data.field.content = content;
        $.ajax({
            url: '{:U('home/jie/ajaxAdd')}',
            type: 'POST',
            dataType: 'json',
            data: data.field,
        })
        .done(function(res) {
            console.log("success");
            if (res.error==1) {
                layer.msg(res.info,function () {
                    // body...
                });
            }else{
                layer.alert("发布成功!!", {icon: 6},function () {
                    // 获得frame索引
                    //var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    //parent.layer.close(index);
                    location.replace(res.url);
                });
            }
            

        })
        .fail(function() {
            console.log("error");
        })
        
        return false;
      });
      
    });




</script>